<?php if (!defined('BASEPATH')) exit('No direct script access allowed.');

/**
 * FORGOT PASSWORD MODEL
 *
 * @author Ali OYGUR <alioygur@gmail.com>
 */
class Forgotpassword_model extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
	}

	public function add($data = array())
	{
		$this->db->insert('forgot_password', $data);
		return $this->db->insert_id();
	}

	public function get($code)
	{
		// delete data from the previous 30 minutes
		self::_delete();

		$query = $this->db->get_where($this->table, array('code' => $code));

		if (!$query->num_rows())
			return false;

		return $query->row();
	}

	/**
	 * 30 dk dan eski satırları siler.
	 * get() fonksiyonu her çağrılmadan önce tetiklenir.
	 */
	private function _delete()
	{
		$this->db->query("DELETE FROM {$this->db->dbprefix($this->table)} WHERE date_add < DATE_ADD(NOW(), INTERVAL -30 MINUTE)");
	}
}

/* End of file forgot_password_model */
